/**
 * 
 */
package com.jquery.ui.tags.javascript.grid;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


import com.jquery.ui.core.base.BaseBodyTag;
import com.jquery.ui.core.bean.UIBean;
import com.jquery.ui.dictionary.IDataType;
import com.jquery.ui.tags.beans.script.GridScriptUI;

/**
 * @author linyajun
 * 
 * @date	2013-10-10
 * @description   
 */
public class GridTag extends BaseBodyTag {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3209151833146776040L;
	
	private String url;
	private String datatype;
	private int rowNum=10;
	private String rowList="[10,20,30]";
	private boolean viewrecords=true;
	private String title; 
	
	private List<String> colNames=new ArrayList<String>(); 
	@Override
	public String getEndTemplate() {
		
		return "grid-script-end.ftl";
	}

	
	public void addColNames(String colName){
		colNames.add(colName);
	}


	@Override
	public String getStartTemplate() {
		
		return "grid-script-start.ftl";
	}

	
	@Override
	public UIBean getUiBean() {
		GridScriptUI grid=new GridScriptUI();
		grid.setUrl(url);
		grid.setDatatype(IDataType.parseValue(datatype));
		grid.setRowNum(rowNum);
		grid.setRowList(rowList);
		grid.setViewrecords(viewrecords);
		grid.setTitle(title);
		return grid;
	}
	
	

	
	@Override
	public void endInvoke(Map<String, Object> attribute) {
		attribute.put("colNames", colNames);
		
	}
	
	@Override
	public void endInvoke() {
		
		removeAll();
	}
	public void removeAll(){
		colNames.removeAll(colNames);
	}


	/**
	 * @return the url
	 */
	public String getUrl() {
		return url;
	}


	/**
	 * @param url the url to set
	 */
	public void setUrl(String url) {
		this.url = url;
	}


	/**
	 * @return the datatype
	 */
	public String getDatatype() {
		return datatype;
	}


	/**
	 * @param datatype the datatype to set
	 */
	public void setDatatype(String datatype) {
		this.datatype = datatype;
	}


	/**
	 * @return the rowNum
	 */
	public int getRowNum() {
		return rowNum;
	}


	/**
	 * @param rowNum the rowNum to set
	 */
	public void setRowNum(int rowNum) {
		this.rowNum = rowNum;
	}


	/**
	 * @return the rowList
	 */
	public String getRowList() {
		return rowList;
	}


	/**
	 * @param rowList the rowList to set
	 */
	public void setRowList(String rowList) {
		this.rowList = rowList;
	}


	/**
	 * @return the viewrecords
	 */
	public boolean isViewrecords() {
		return viewrecords;
	}


	/**
	 * @param viewrecords the viewrecords to set
	 */
	public void setViewrecords(boolean viewrecords) {
		this.viewrecords = viewrecords;
	}


	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}


	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}
	
	

}
